//路由的核心js文件
//创建路由的实例，同时要配置路由
//1.将组件与url进行绑定
//通过url=>登录组件

//导入路由的函数
import {createRouter,createWebHistory} from 'vue-router'
import Login from "../views/Login.vue";
import Home from "../views/Home.vue";
import Index from "../components/Index.vue";
import about from "@/components/About.vue";
import Contact from "@/components/Contact.vue";
import Service from "@/components/Service.vue";
//创建路由的实例
const router = createRouter({
  history: createWebHistory(),
  routes:[ //路由数组，配置组件与路由的绑定
    {
      path: '/login', //登录的url，必须是唯一的
      name: 'login', // 路由名称
      component: Login, //组件
    },
    {
      path: '/', //登录组件
      redirect: '/login'//重定向到 '/'
    },
    {
      path: '/home', //主页面组件
      name: 'home',
      component: Home,//立即加载
      //嵌套路由：二级路由
      children: [
        {
          path: 'index',//首页路由，访问：/home/index
          //component: ()=>import('../components/Index.vue'),//首页组件，立即加载
          component: Index,//立即加载
        },
        {
          path: 'about',// /home/about
          // component: ()=>import('../components/About.vue')
          component: about,//立即加载
        },
        {
          path: 'Contact',
          //component: ()=>import('../components/Index.vue'),//首页组件，立即加载
          component: Contact,//立即加载
        },
        {
          path: 'Service',// /home/about
          // component: ()=>import('../components/About.vue')
          component: Service,//立即加载
        },
      ]
    },
    {
      path: '/register',//注册组件
      name: 'register',
      component: ()=>import('../views/Register.vue')//懒加载组件
    }
  ]
})
//导出路由
export default router